﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.Common.Model;
using Yipusoft.Common.BLL;
using Yipusoft.SoldierArchives.BLL;

public partial class Police_TransferQurey : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            init();
        }
    }

    private void init()
    {
        //今年士兵调动情况
        lblCaption.Text = DateTime.Now.Year.ToString() + "年士兵调动情况";
        lblNow.Text = DateTime.Now.ToLongDateString();
        //调入
        hyDR.Text = TransferSoldier.GetTransfersCountByWhere("( FromJingZhong in ('SBDD11','SBDD12')) and TransferDate>= '" + DateTime.Now.Year + "-1-1'").ToString();
        hyDR.NavigateUrl = "TransferQureyResult.aspx?where=(FromJingZhong in ('SBDD11','SBDD12')) and TransferDate>= '" + DateTime.Now.Year + "-1-1'";
        hyDRXF.Text = TransferSoldier.GetTransfersCountByWhere("( FromJingZhong='SBDD12') and TransferDate>= '" + DateTime.Now.Year + "-1-1'").ToString();
        hyDRXF.NavigateUrl = "TransferQureyResult.aspx?where=(FromJingZhong='SBDD12') and TransferDate>= '" + DateTime.Now.Year + "-1-1'";
        hyDRQT.Text = TransferSoldier.GetTransfersCountByWhere("( FromJingZhong='SBDD11') and TransferDate>= '" + DateTime.Now.Year + "-1-1'").ToString();
        hyDRQT.NavigateUrl = "TransferQureyResult.aspx?where=(FromJingZhong='SBDD11') and TransferDate>= '" + DateTime.Now.Year + "-1-1'";
        //调出
        hyDC.Text = TransferSoldier.GetTransfersCountByWhere("( ToJingZhong in ('SBDD21','SBDD22')) and TransferDate>= '" + DateTime.Now.Year + "-1-1'").ToString();
        hyDC.NavigateUrl = "TransferQureyResult.aspx?where=( ToJingZhong in ('SBDD21','SBDD22')) and TransferDate>= '" + DateTime.Now.Year + "-1-1'";
        hyDCXF.Text = TransferSoldier.GetTransfersCountByWhere("( ToJingZhong='SBDD22') and TransferDate>= '" + DateTime.Now.Year + "-1-1'").ToString();
        hyDCXF.NavigateUrl = "TransferQureyResult.aspx?where=( ToJingZhong='SBDD22') and TransferDate>= '" + DateTime.Now.Year + "-1-1'";
        hyDCQT.Text = TransferSoldier.GetTransfersCountByWhere("( ToJingZhong='SBDD21') and TransferDate>= '" + DateTime.Now.Year + "-1-1'").ToString();
        hyDCQT.NavigateUrl = "TransferQureyResult.aspx?where=( ToJingZhong='SBDD21') and TransferDate>= '" + DateTime.Now.Year + "-1-1'";
        //省内
        hyNB.Text = TransferSoldier.GetTransfersCountByWhere("(LEFT(ToUnitID, 4) <> LEFT(FromUnitID, 4)) and ( FromJingZhong='SBDD30') and ToJingZhong='SBDD30' and TransferDate>= '" + DateTime.Now.Year + "-1-1'").ToString();
        hyNB.NavigateUrl = "TransferQureyResult.aspx?where=(LEFT(ToUnitID, 4) <> LEFT(FromUnitID, 4)) and ( FromJingZhong='SBDD30') and ToJingZhong='SBDD30' and TransferDate>= '" + DateTime.Now.Year + "-1-1'";

        //时间范围查询
        BindDateTime();
        startYear.SelectedValue = DateTime.Now.Year.ToString();
        EndYear.SelectedValue = DateTime.Now.Year.ToString();
        startMonth.SelectedValue = "1";
        EndMonth.SelectedValue = DateTime.Now.Month.ToString();
        BindRanger();
    }

    void BindDateTime()
    {
        for (int i = 2008; i <= 2050; i++)
        {
            startYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
            EndYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
        }
        for (int i = 1; i <= 12; i++)
        {
            startMonth.Items.Add(new ListItem(i.ToString(), i.ToString()));
            EndMonth.Items.Add(new ListItem(i.ToString(), i.ToString()));
        }
    }

    private void BindTransferType(CheckBoxList cbl, string parentID)
    {
        List<CodeItemInfo> codeItems = CodeItem.GetList("parentID='" + parentID + "' order by seqID");
        cbl.DataTextField = "ItemName";
        cbl.DataValueField = "ItemID";
        cbl.DataSource = codeItems;
        cbl.DataBind();

    }

    private string GetDepartmentID()
    {
        string departmentID = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID;
        if (Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "400101"))
            departmentID = departmentID.Substring(0, 2) + "00000";
        else
            if (Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "400102"))
                departmentID = departmentID.Substring(0, 4) + "000";
        return departmentID;
    }

    

    bool isAdmin()
    {
        string departmentID = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID;
        if (Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "400101"))
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    bool isOfferSet()
    {
        string departmentID = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID;
        if (Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "400102"))
        {
            return true;
        }
        else
        {
            return false;
        }
    }


   
    protected void startYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindRanger();

    }
    protected void startMonth_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindRanger();
    }
    protected void EndYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindRanger();
    }
    protected void EndMonth_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindRanger();
    }

    void BindRanger()
    {
        DateTime startTime = Convert.ToDateTime(startYear.SelectedValue + "-" + startMonth.SelectedValue + "-1");
        DateTime endTime = Convert.ToDateTime(EndYear.SelectedValue + "-" + EndMonth.SelectedValue + "-1").AddMonths(1);
        string TransferDate = " and TransferDate>='" + startTime.ToShortDateString() + "' and TransferDate<'" + endTime.ToShortDateString() + "' ";
        //调入
        string DR0 = "( FromJingZhong in ('SBDD11','SBDD12'))" + TransferDate; ;
        hyDR0.Text = TransferSoldier.GetTransfersCountByWhere(DR0).ToString();
        hyDR0.NavigateUrl = "TransferQureyResult.aspx?where=" + DR0;
        string DRXF0 = "( FromJingZhong='SBDD12')" + TransferDate;
        hyDRXF0.Text = TransferSoldier.GetTransfersCountByWhere(DRXF0).ToString();
        hyDRXF0.NavigateUrl = "TransferQureyResult.aspx?where=" + DRXF0;
        string strDRQT0 = "( FromJingZhong='SBDD11')" + TransferDate;
        hyDRQT0.Text = TransferSoldier.GetTransfersCountByWhere(strDRQT0).ToString();
        hyDRQT0.NavigateUrl = "TransferQureyResult.aspx?where=" + strDRQT0;
        //调出
        string DC0 = "( ToJingZhong in ('SBDD21','SBDD22'))" + TransferDate;
        hyDC0.Text = TransferSoldier.GetTransfersCountByWhere(DC0).ToString();
        hyDC0.NavigateUrl = "TransferQureyResult.aspx?where=" + DC0;
        string DCXF0 = "( ToJingZhong='SBDD22')" + TransferDate;
        hyDCXF0.Text = TransferSoldier.GetTransfersCountByWhere(DCXF0).ToString();
        hyDCXF0.NavigateUrl = "TransferQureyResult.aspx?where=" + DCXF0;

        string DCQT0 = "( ToJingZhong='SBDD21')" + TransferDate;
        hyDCQT0.Text = TransferSoldier.GetTransfersCountByWhere(DCQT0).ToString();
        hyDCQT0.NavigateUrl = "TransferQureyResult.aspx?where=" + DCQT0;
        //省内
        string NB0 = "(LEFT(ToUnitID, 4) <> LEFT(FromUnitID, 4)) and ( FromJingZhong='SBDD30') and ToJingZhong='SBDD30'" + TransferDate;
        hyNB0.Text = TransferSoldier.GetTransfersCountByWhere(NB0).ToString();
        hyNB0.NavigateUrl = "TransferQureyResult.aspx?where=" + NB0;

    }
}
